package org.linuxsogood.boot.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

/**
 * @author liu.hongwei
 */
public class NioClient {

    public static void main(String[] args) throws IOException {
        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.configureBlocking(false);

        socketChannel.connect(new InetSocketAddress("127.0.0.1", 6666));
        if (!socketChannel.isConnected()) {
            while (!socketChannel.finishConnect()) {
                System.out.println("not connect to server...");
            }
        }
        System.out.println("connect finished...");
        socketChannel.write(ByteBuffer.wrap("Hello NioServer".getBytes()));

    }
}
